/// <reference path="../typings/index.d.ts" />
/// <reference path="../src/carService.ts" />
/// <reference path="../src/tms.ts" />

describe('getCarList',() => {
    var injector:ng.auto.IInjectorService;
    var service:ICarService;

    beforeEach(() => {
        injector = angular.injector(['ng','tms']);
        service = injector.get<ICarService>('carService');
    });

    //常规无条件获取
    it('get car list normal',(done) => {
        service.getList(null, null, null, null,null,null,null,null,null,null,null, 0, 10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取排序字段枚举包含 1 的车辆列表
    it('get car list by orderBy \'1\'',(done) => {
        service.getList('1',null,null,null,null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|||||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取升序的车辆列表
    it('get car list by asc \'true\'',(done) => {
        service.getList(null,true,null,null,null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|true||||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取车牌号包含A的车辆列表
    it('get car list by carCode \'A\'',(done) => {
        service.getList(null,null,'A',null,null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||A|||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //获取车型包含 厢车 的车辆列表
    it('get car list by carType \'厢车\'',(done) =>{
        service.getList(null,null,null,'厢车',null,null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||厢车||||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取车长包含 4.2米 的车辆列表
    it('get car list by carLength \'4.2米\'',(done) =>{
        service.getList(null,null,null,null,'4.2米',null,null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||4.2米|||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取录入人包含 测试 的车辆列表
    it('get car list by inputPerson \'测试\'',(done) =>{
        service.getList(null,null,null,null,null,'测试',null,null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||测试||||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取驾驶员包含 胡 的车辆列表
    it('get car list by driver \'胡\'',(done) =>{
        service.getList(null,null,null,null,null,null,'胡',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||||胡|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取驾驶员号码包含 7 的车辆列表
    it('get car list by driverPhone \'7\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,'7',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||||7||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    }); 

    //获取承运类别包含 整车 的车辆列表
    it('get car list by carrierCategory \' 整车\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,null,'整车',null,null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||||||整车|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });  

    //获取主营路线包含 镇江 的车辆列表
    it('get car list by mainRoute \'镇江\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,null,null,'镇江',null,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('|||||||||镇江||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    }); 

    //获取是否启用包含 禁用 的车辆列表
    it('get car list by isEnabled  \'false\'',(done) =>{
        service.getList(null,null,null,null,null,null,null,null,null,null,false,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||||||||||false|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    }); 

    //获取排序字段枚举包含 1,升序,车牌号包含苏L00001,车型包含厢车，车长包含4.5米 ，录入人包含测试，驾驶员包含胡，驾驶员号码包含7，承运类别包含 整车，主营路线包含 镇江，禁用 的车辆列表
    it('get car list by orderBy \'1\' and asc \'true\' and carCode \'苏L00001\' and carType \'厢车\' and carLength \'4.5米\' and inputPerson \'测试\' and driver \'胡\' and driverPhone \'7\' and carrierCategory \'整车\' and mainRoute \'镇江\' and isEnabled \'false\'',(done) => {
        service.getList('1',true,'苏L00001','厢车','4.5米','测试','胡','7','整车','镇江',false,0,10).then((res) => {
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('1|true|苏L00001|厢车|4.5米|测试|胡|7|整车|镇江|false|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });



    //获取车辆详情
    it('get detail',(done)=>{
        service.getDetail('2').then((res)=>{
            expect(res.data.carCode).toBe("苏L00001");
            expect(res.data.carType).toBe("厢车");
            expect(res.data.carLength).toBe("4.5米");
            expect(res.data.driver).toBe("胡");
            expect(res.data.driverPhone).toBe("7");
            expect(res.data.carriageType).toBe("整车");
            expect(res.data.bearing).toBe("2");
            expect(res.data.carSource).toBe("买");
            expect(res.data.address).toBe("镇江");
            expect(res.data.attachmentList[0].attachmentId).toBe("1");
            expect(res.data.attachmentList[0].attachmentName).toBe("名称");
            expect(res.data.attachmentList[0].attachmentPath).toBe("路径");
            expect(res.data.attachmentList[0].attachmentTag).toBe("tag");
            expect(res.data.locationStatus).toBe(true);
            expect(res.data.average).toBe(100);
            expect(res.data.praiseCount).toBe(30);
            expect(res.data.isEnabled).toBe(false);
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //添加车辆 
    it('add car',(done)=>{
        service.add('苏L999999','厢车','4.2米','王毅','183528683333','整车',2,'买','镇江').then((res)=>{
            expect(res.data.extData).toBe('苏L999999|厢车|4.2米|王毅|183528683333|整车|2|买|镇江');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //编辑车辆
    it('edit car',(done)=>{
        service.edit('2','苏L888888','厢车','4.2米','王毅','183528683333','整车',2,'买','镇江').then((res)=>{
            expect(res.data.extData).toBe('2|苏L888888|厢车|4.2米|王毅|183528683333|整车|2|买|镇江');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //删除车辆
    it('delete car',(done)=>{
        service.delete('3').then((res)=>{
            expect(res.data.extData).toBe("3");
            done();
        },(err)=>{
            done.fail(err);
        });
    });


    //获取车牌号包含苏L00001 的交易记录
    it('get tradingRecord list by carcode \'苏L00001\'',(done)=>{
        service.getTradingRecordList('苏L00001',null,null,null,null,null,0,10).then((res)=>{  
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L00001||||||0|10');        
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L00001 ,货物名称包含货物 的交易记录
    it('get tradingRecord list by carcode \'苏L00001\' and goodsname \'货物\'',(done) => {
        service.getTradingRecordList('苏L00001','货物',null,null,null,null,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L00001|货物|||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L00001 ，货物数量包含1立方 的交易记录
    it('get tradingRecord list by carcode \'苏L00001\' and goodsnum \'1立方\'',(done) => {
        service.getTradingRecordList('苏L00001',null,'1立方',null,null,null,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L00001||1立方||||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L19980 ,线路地址包含江苏 的交易记录
    it('get tradingRecord list by carcode \'苏L19980\' and route \'江苏\'',(done) => {
        service.getTradingRecordList('苏L19980',null,null,'江苏',null,null,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980|||江苏|||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L19980 ,发货地址包含 江苏 的交易记录
    it('get tradingRecord list by carcode \'苏L19980\' and shipaddress \'江苏\' ',(done) => {
        service.getTradingRecordList('苏L19980',null,null,null,'江苏',null,0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980||||江苏||0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L19980 ,送货地址包含 镇江 的交易记录
    it('get tradingRecord list by carcode \'苏L19980\' and deliveraddress \'镇江\' ',(done) => {
        service.getTradingRecordList('苏L19980',null,null,null,null,'镇江',0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980|||||镇江|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L19980 ,货物名称包含货物，货物数量包含1立方,线路地址包含北京,发货地址包含 江苏, 送货地址包含 镇江 的交易记录
    it('get tradingRecord list by carcode \'苏L19980\' and  goodsname \'货物\' and  goodsnum \'1立方\' and route \'北京\' and shipaddress \'江苏\' and deliveraddress \'镇江\'',(done) => {
        service.getTradingRecordList('苏L19980','货物','1立方','北京','江苏','镇江',0,10).then((res) => {
            expect(res.data.total).toBe(10);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980|货物|1立方|北京|江苏|镇江|0|10');
            done();
        },(err) => {
            done.fail(err);
        });
    });


    //常规无条件获取诚信记录
    it('get evaluate list normal',(done)=>{
        service.getEvaluateList(null,null,0,10).then((res)=>{  
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('||0|10');           
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //获取车牌号包含苏L19980 的诚信记录  
    it('get evaluate list by carCode \'苏L19980\' ',(done)=>{
        service.getEvaluateList('苏L19980',null,0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980||0|10');  
            done(); 
        },(err)=>{
            done.fail(err);
        });
    });

    //获取 车牌号包含苏L19980 ,评价人编号包含 2 的诚信记录  
    it('get evaluate list  by carCode \'苏L19980\' and appraiserId \'2\' ',(done)=>{
        service.getEvaluateList('苏L19980','2',0,10).then((res)=>{
            expect(res.data.total).toBeGreaterThan(0);
            expect(res.data.list.length).toBe(10);
            expect(res.data.extData).toBe('苏L19980|2|0|10');  
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    //修改启用状态
    it('change enable',(done)=>{
        service.enabled('2',true).then((res)=>{
            expect(res.data.extData).toBe('2|true');
            done();
        },(err)=>{
            done.fail(err);
        });
    });

    
    //添加附件
    it('add attachment',(done)=>{
        service.addAttachment('2',[{attachmentId:'1',attachmentName:'name',attachmentPath:'path',attachmentTag:'tag'}]).then((res)=>{
            expect(res.data.extData).toBe("2|1|name|path|tag");
            done();
        },(err)=>{
            done.fail(err);
        });
    });

});